<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:64:"E:\WWW\waimai/app/admin/shop\view\shop_goods_category\index.html";i:1502185032;s:52:"E:\WWW\waimai/app/admin/shop\view\template\base.html";i:1495522842;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="__STATIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <!--图标字体元件库-->
    <link rel="stylesheet" href="__STATIC__/plugins/font-awesome4.5.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/AdminLTE.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/jquery.datetimepicker.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/validform/5.3.2/css/Validateform_v5.3.2.css">

    <link rel="stylesheet" href="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/polaris/polaris.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/futurico/futurico.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/line/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/square/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/flat/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/minimal/_all.css">
    

    <title><?php echo \think\Config::get('site.title'); ?></title>
    

    <script src="__STATIC__/plugins/jquery/jquery-3.0.0.min.js"></script>
    <script src="__STATIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="__STATIC__/admin/js/app.min.js"></script>
    <script src="__STATIC__/admin/extend/app.js"></script>

    <script src="__STATIC__/admin/extend/H-ui.admin.js"></script>
    <script src="__STATIC__/plugins/layer3.0.3/layer.js"></script>
    <script src="__STATIC__/plugins/validform/5.3.2/Validform_v5.3.2_min.js"></script>

    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table-zh-CN.js" type="text/javascript"></script>

    <script src="__STATIC__/plugins/iCheck/icheck.min.js"></script>
    <script>

        var admin_menu_data=<?php if(isset($admin_menu)): ?><?php echo $admin_menu; endif; ?>;
        $(function () {
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            });
        })
    </script>

    
</head>
<body class="hold-transition skin-blue-light sidebar-mini">
    
<div class="row">
    <div class="col-xs-12">
        <div class="box-body">
            <div class="row">
                <div class="col-xs-1">
                    <button type="button" class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 添加分类
                    </button>
                </div>
                <div class="col-xs-3">
                    <div class="input-group col-xs-12">
                        <span class="input-group-addon">关键字</span>
                        <input type="text" class="form-control" id="keyword" placeholder="分类名称、店铺"/>
                    </div>
                </div>
                <div class="col-xs-1">
                    <div class="input-group col-xs-12">
                        <select class="form-control select2" id="sel_status">
                            <option selected="selected" value="-1">全部状态</option>
                            <option value="0">失效</option>
                            <option value="1">有效</option>
                        </select>
                    </div>
                </div>
                <?php if(empty($sid)): ?>
                <div class="col-xs-1">
                    <div class="input-group col-xs-12">
                        <select class="form-control select2 store">
                            <option selected="selected" value="-1">全部商家</option>
                            <?php if(is_array($store['rows']) || $store['rows'] instanceof \think\Collection || $store['rows'] instanceof \think\Paginator): $i = 0; $__LIST__ = $store['rows'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                            <option value="<?php echo $vo['id']; ?>"><?php echo $vo['text']; ?></option>
                            <?php endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
                <?php else: ?>
                <input type="hidden" class="store" value="<?php echo $sid; ?>">
                <?php endif; ?>
                <div class="col-xs-1">
                    <button type="button" class="btn btn-primary" id="btn_search"><i
                            class="glyphicon glyphicon-search"></i> 搜索
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-body">
                <table id="table"
                       data-toggle="table"
                       data-striped ="true"
                       data-query-params = "requestParam"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-id-field="id"
                       data-url="<?php echo url('ShopGoodsCategory/index_data'); ?>"
                >
                    <thead>
                    <tr>
                        <th data-field="sname">店铺</th>
                        <th data-field="name">分类名称</th>
                        <th data-field="goods_num">商品数量</th>
                        <th data-field="sort" data-sortable="true">排序</th>
                        <th data-field="flag_use" data-formatter="format_flag_use">状态</th>
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

    </div><!-- /.col -->
</div><!-- /.row -->

</body>
<script src="__STATIC__/admin/js/skins_control.js"></script>
<script src="__STATIC__/admin/js/jquery.datetimepicker.js"></script>

<script>
    var add_data_url="<?php echo url('ShopGoodsCategory/add'); ?>";
    var edit_data_url="<?php echo url('ShopGoodsCategory/edit'); ?>";
    var delete_data_url="<?php echo url('ShopGoodsCategory/delete'); ?>";
</script>
<script>
    // <editor-fold defaultstate="collapsed" desc="格式化url">
    function urlFormat(url) {
        if( url.indexOf('.html')){
            url=url.replace('.html','')
        }
        return url;
    }
    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="查询">

    $("#sel_status").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })
    $("#store").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })
    //搜索按钮事件
    $("#btn_search").on('click', function () {
        $('#table').bootstrapTable('refresh');
    })

    var temp = {};
    function requestParam(params) {
        temp = {
            limit: params.limit, //页面大小
            offset: params.offset, //页码
            order: params.order,
            sort: params.sort,
            search: $("#keyword").val(),
            store: $(".store").val(),
            status: $("#sel_status").val()
        };
//        console.log(temp);
        return temp;
    }

    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function () {
        layer_open('添加',urlFormat(add_data_url)+"/sid/<?php echo $sid; ?>",{w:"800px",h:"350px"})
    });
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作按钮">
    function formatOperate(value,row,index){
        console.log(row)
        if(row.isdefault == 1){
            return [
                '<button class="btn btn-default btn-xs" href="javascript:void(0)" disabled="disabled">',
                '<i class="fa fa-edit"></i> 修改',
                '</button>&nbsp;',
                '<button class="btn btn-default btn-xs" href="javascript:void(0)" disabled="disabled">',
                '<i class="fa fa-trash"></i> 删除',
                '</button>'
            ].join('');
        }else{
            return [
                '<button class="btn btn-warning btn-xs row_edit" href="javascript:void(0)">',
                '<i class="fa fa-edit"></i> 修改',
                '</button>&nbsp;',
                '<button class="btn btn-danger btn-xs row_delete" href="javascript:void(0)">',
                '<i class="fa fa-trash"></i> 删除',
                '</button>'
            ].join('');
        }
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_edit': function (e, value, row, index) {
            layer_open('更改分类信息',urlFormat(edit_data_url)+"/id/"+row.id+"/num/"+row.goods_num+"/sid/<?php echo $sid; ?>",{w:"800px",h:"350px"});
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('该分类下的商品将会移至"未分类"下<br/>你确定要删除该选项吗？',{btn:['确定','取消']},function () {
                $.ajax({
                    dataType:'json',
                    data:{id:row.id,store_id:row.store_id},
                    url:delete_data_url,
                    success:function (res) {
                        if(res.success){
                            layer.msg(res.message, {time: 1000},function () {
                                $('#table').bootstrapTable('refresh');
                            });
                        }else{
                            layer.alert(res.message);
                        }
                    }
                })
            })
        },
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="状态格式化">
    function format_flag_use(value) {
        switch(value){
            case 1:
                return '<i class="fa fa-check-circle text-green" title="有效">有效</i>';break;
            case 0:
                return '<i class="fa fa-minus-circle text-yellow" title="失效">失效</i>';break;
        }

    }
    // </editor-fold>

</script>

</html>